package com.mf.controller.basic.webPage;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.mf.aspect.debounces.Debounce;
import com.mf.aspect.logApi.LogApi;
import com.mf.groups.GroupsAddInterface;
import com.mf.groups.GroupsUpdateInterface;
import com.mf.result.Result;
import com.mf.utils.UtilConverter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.entity.dto.basic.webPage.DtoPageJsonConfig;
import com.mf.entity.req.basic.webPage.ReqPageJsonConfig;
import com.mf.service.basic.webPage.ServicePageJsonConfig;
import com.mf.entity.req.basic.search.webPage.SearchReqPageJsonConfig;

import java.util.List;

/**
 * json格式配置
 */
@RestController
@RequestMapping("pageJsonConfig")
@Tag(name = "json格式配置")
@SaCheckLogin
@Debounce
public class ControllerPageJsonConfig {
    @Resource
    private ServicePageJsonConfig servicepageJsonConfig;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    @SaCheckPermission("pageJsonConfig:search")
    public Result<Page<DtoPageJsonConfig>> findPage(@RequestBody SearchReqPageJsonConfig searchReqPageJsonConfig) {
        return Result.success(servicepageJsonConfig.findPageByParams(searchReqPageJsonConfig));
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission("pageJsonConfig:search")
    @PostMapping("/list")
    public Result<List<DtoPageJsonConfig>> list(@RequestBody SearchReqPageJsonConfig searchReqPageJsonConfig) {
        return Result.success(servicepageJsonConfig.findListByParams(searchReqPageJsonConfig));
    }
    @Operation(summary = "根据id查询")
    @SaCheckPermission("pageJsonConfig:search")
    @GetMapping("find/{id}")
    public Result<DtoPageJsonConfig> findById(@PathVariable Integer id) {
        return Result.success(servicepageJsonConfig.getById(id));
    }

    @Operation(summary = "保存")
    @SaCheckPermission("pageJsonConfig:edit")
    @LogApi("保存json格式配置")
    @PostMapping("/save")
    public Result<DtoPageJsonConfig> save(@Validated(GroupsAddInterface.class) @RequestBody ReqPageJsonConfig reqPageJsonConfig) {
        return Result.success(servicepageJsonConfig.saveConfig(UtilConverter.converter(reqPageJsonConfig, DtoPageJsonConfig.class)));
    }



    @Operation(summary = "修改")
    @SaCheckPermission("pageJsonConfig:edit")
    @LogApi("修改json格式配置")
    @PostMapping("/update")
    public Result<DtoPageJsonConfig> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqPageJsonConfig reqPageJsonConfig) {
        DtoPageJsonConfig pageJsonConfig = UtilConverter.converter(reqPageJsonConfig, DtoPageJsonConfig.class);
        servicepageJsonConfig.updateById(pageJsonConfig);
        return Result.success(pageJsonConfig);
    }
    @Operation(summary = "复制配置")
    @SaCheckPermission("pageJsonConfig:edit")
    @LogApi("复制配置")
    @GetMapping("/copy")
    public Result<Void> copy(@RequestParam Integer id) {
        servicepageJsonConfig.copy(id);
        return Result.success();
    }



    @Operation(summary = "删除")
    @SaCheckPermission("pageJsonConfig:delete")
    @LogApi("删除json格式配置")
    @GetMapping("/delete/{id}")
    public Result<Void> delete(@PathVariable("id") Integer id) {
        servicepageJsonConfig.deleteById(id);
        return Result.success();
    }
}
